﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using CSUI.Forms;
using CSUI.Images;

namespace CSUI
{
    public partial class FormIn : Form
    {
        public delegate void Deleyymm(string yy, string mm);
        bool status;
        int panlleftinit;
        private const int CS_DropSHADOW = 0x20000;
        private const int GCL_STYLE = (-26);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);

        private void SetShadow()
        {
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
        }

        public FormIn()
        {

            InitializeComponent();
            //阴影
            SetShadow();
            //侧边栏
            panlleftinit = Paneleft.Width;
            status = false;
            TimeDate.Start();
           

            //初始化窗口
            OneForm frm1 = new OneForm();
            AddPanelz(frm1);
            btnsen(bt1);
            btnsen(bt2);
            btnsen(bt3);
            btnsen(bt4);
            btnsen(bt5);
        }

        public void InitTime()
        {
            CommClass.DataBind(cbyy, "YY");
            CommClass.DataBind(cbmm, "MM");
            Deleyymm dyymm = new Deleyymm(CommClass.Fzyymm);
            dyymm(cbyy.SelectedValue.ToString(), cbmm.SelectedValue.ToString());
            CommClass.DataBind(cbdd, "DD");
            cbyy.SelectedValue = DateTime.Now.Year.ToString();
            cbmm.SelectedValue = DateTime.Now.Month.ToString();
            cbdd.SelectedValue = DateTime.Now.Day.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        private void AddPanelz(Control c)
        {
            c.Dock = DockStyle.Fill;
            paneControl.Controls.Clear();
            paneControl.Controls.Add(c);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OneForm frm1 = new OneForm();
            AddPanelz(frm1);
        }

        private void btnsen(Button btn)
        {
            btn.MouseMove += ((sender, s) =>
            {
                paneside.Top = btn.Top;
                paneside.Height = btn.Height;
            });
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.TimeColose.Start();
        }

        private void bt2_Click(object sender, EventArgs e)
        {
            TwoForm frm2 = new TwoForm();
            AddPanelz(frm2);
        }

        private void TimeDate_Tick(object sender, EventArgs e)
        {
            lbTime.Text = DateTime.Now.ToString("yyyy年MM月dd日 HH点mm分ss秒");
        }

        private void FormIn_Load(object sender, EventArgs e)
        {
            InitTime();
        }

        private void TimeColose_Tick(object sender, EventArgs e)
        {
            if (status)
            {
                Paneleft.Width += 20;
                if (Paneleft.Width >= panlleftinit)
                {
                    TimeColose.Stop();
                    status = false;
                    this.Refresh();
                }
            }
            else
            {
                Paneleft.Width -= 20;
                if (Paneleft.Width <= 64)
                {
                    TimeColose.Stop();
                    status = true;
                    this.Refresh();
                }
            }
        }
    }
}
